<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ page import="projects.task" %>
<%@ page import="userInteraction.readUserInformation" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<jsp:useBean id="change" class="projects.task"></jsp:useBean>
<jsp:setProperty property="*" name="change"/>
<jsp:useBean id="userId" class="userInteraction.readUserInformation"></jsp:useBean>
<jsp:setProperty property="*" name="userId"/>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

<%
	if (session.getAttribute("loggedIn") == null) {
		response.sendRedirect("../User/index.jsp");
		}
%>

</body>

<%
	task tsk = new task();
	tsk.setTaskId(Integer.parseInt(session.getAttribute("taskId").toString()));
	readUserInformation userInfo = new readUserInformation(); 
	tsk.setStatusId(Integer.parseInt(request.getParameter("taskStatus")));
	tsk.setResolutionId(Integer.parseInt(request.getParameter("taskResolution")));
	
	String url = "../Tasks/task.jsp?id="+tsk.getTaskId();
	if(request.getParameter("hEmployeeId") == ""){
		if (tsk.updateTaskStatusAndResolution(userInfo.readUserId(session.getAttribute("loggedIn").toString()), 1) == true && tsk.assignEmployeeToTask(1)){
			session.setAttribute("postback", "true");
			session.setAttribute("changeStatusResolution", "true");
			response.sendRedirect(url); 
		}
		else
		{
			session.setAttribute("postback", "true");
			session.setAttribute("changeStatusResolution", "false");
			response.sendRedirect(url);
		}	
	}
	else if (tsk.updateTaskStatusAndResolution(userInfo.readUserId(session.getAttribute("loggedIn").toString()), Integer.parseInt(request.getParameter("hEmployeeId"))) == true && tsk.assignEmployeeToTask(Integer.parseInt(request.getParameter("hEmployeeId")))){
		session.setAttribute("postback", "true");
		session.setAttribute("changeStatusResolution", "true");
		response.sendRedirect(url); 
	}
	else
	{
		session.setAttribute("postback", "true");
		session.setAttribute("changeStatusResolution", "false");
		response.sendRedirect(url);
	}
%>

</html>